<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
<!--    <div class="table-page-search-wrapper">-->
<!--      <a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--        <a-row :gutter="24">-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-model-item label="科目" prop="subjectId">-->
<!--              <j-dict-select-tag v-model="serchParams.subjectId" placeholder="请选择科目" dictCode="cou_subject,subject_name,id"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->

<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-model-item label="所属试卷" prop="examinationPaperId">-->
<!--              <j-dict-select-tag v-model="serchParams.examinationPaperId" placeholder="请选择所属考试" dictCode="ach_examination,examination_name,id"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->

<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-model-item label="项目类型" prop="exaPapProItemTtype">-->
<!--              <j-dict-select-tag type="list"  v-model="serchParams.exaPapProItemTtype" placeholder="选择项目类型" dictCode="exa_pap_pro_item_ttype"/>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
<!--              <a-button type="primary" @click="whereSerchAchExaPaperProject" icon="search">查询</a-button>-->
<!--              <a-button type="primary" @click="whereSerchAchExaPaperProjectInit" icon="reload" style="margin-left: 8px">重置</a-button>-->
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
<!--            </span>-->
<!--          </a-col>-->
<!--        </a-row>-->
<!--      </a-form>-->
<!--    </div>-->
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增题型项</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('ach_exam_paper_project_item')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ach-exam-paper-project-item-modal ref="modalForm" @ok="modalFormOk"></ach-exam-paper-project-item-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AchExamPaperProjectItemModal from './modules/AchExamPaperProjectItemModal'
  import { getAction } from '@api/manage'

  export default {
    name: 'AchExamPaperProjectItemList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      AchExamPaperProjectItemModal
    },
    data () {
      return {
        description: 'ach_exam_paper_project_item管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'所属试卷名称',
            align:"center",
            dataIndex: 'examinationPaperName'
          },
          {
            title:'科目',
            align:"center",
            dataIndex: 'subjectName'
          },
          {
            title:'试卷项目编码',
            align:"center",
            dataIndex: 'exaPapProItemCode'
          },
          {
            title:'题型项目名称',
            align:"center",
            dataIndex: 'exaPapProItemName'
          },
          {
            title:'题型项目满分',
            align:"center",
            dataIndex: 'exaPapProItemFullMarks'
          },
          {
            title:'题型类型',
            align:"center",
            dataIndex: 'exaPapProItemTtype_dictText'
          },
          {
            title:'主客类型',
            align:"center",
            dataIndex: 'exaPapProItemSubTtype_dictText'
          },
          // {
          //   title:'项目级别',
          //   align:"center",
          //   dataIndex: 'exaPapProItemLevel_dictText'
          // },
          // {
          //   title:'上级项目',
          //   align:"center",
          //   dataIndex: 'exaPapProItemFatherId'
          // },
          {
            title:'项目序号',
            align:"center",
            sorter: true,
            dataIndex: 'exaPapProItemOrder'
          },
          {
            title:'是否启用',
            align:"center",
            dataIndex: 'izOpen_dictText'
          },
          // {
          //   title:'所属部门',
          //   align:"center",
          //   dataIndex: 'sysOrgName'
          // },
          // {
          //   title:'是否删除',
          //   align:"center",
          //   dataIndex: 'delFlag_dictText'
          // },
          // {
          //   title:'创建人',
          //   align:"center",
          //   dataIndex: 'createBy'
          // },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          // {
          //   title:'修改人',
          //   align:"center",
          //   dataIndex: 'updateBy'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          // list1212: "/achexampaperprojectitem/achExamPaperProjectItem/list",
          list: "/achexampaperprojectitem/achExamPaperProjectItem/listVoAll",
          list2: "/achexampaperprojectitem/achExamPaperProjectItem/getAchExamProjectItemByPaperId",
          delete: "/achexampaperprojectitem/achExamPaperProjectItem/delete",
          deleteBatch: "/achexampaperprojectitem/achExamPaperProjectItem/deleteBatch",
          exportXlsUrl: "/achexampaperprojectitem/achExamPaperProjectItem/exportXls",
          importExcelUrl: "achexampaperprojectitem/achExamPaperProjectItem/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        //条件查询参数
        serchParams: {
          id: null,
          subjectId: null,
          examinationPaperId: null,
          exaPapProItemCode: null,
          exaPapProItemName: null,
          exaPapProItemFullMarks: null,
          exaPapProItemTtype: null,
          exaPapProItemSubTtype: null,
          exaPapProItemLevel: null,
          exaPapProItemFatherId: null,
          exaPapProItemOrder: null,
          izOpen: null,
          sysOrgCode: null,
          tenantId: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
        },
        objectModel: {
          id: null
        },
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //条件查询
      whereSerchAchExaPaperProject(){
        this.getAchExaminationPaperData()
      },
      //重置查询条件
      whereSerchAchExaPaperProjectInit(){
        this.serchParams = []
        this.getAchExaminationPaperData()
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'subjectId',text:'科目id',dictCode:''})
        fieldList.push({type:'string',value:'examinationPaperId',text:'试卷id',dictCode:''})
        fieldList.push({type:'string',value:'exaPapProItemCode',text:'考试项目编码(必填，非空)',dictCode:''})
        fieldList.push({type:'string',value:'exaPapProItemName',text:'考试项目名称',dictCode:''})
        fieldList.push({type:'double',value:'exaPapProItemFullMarks',text:'项目满分',dictCode:''})
        fieldList.push({type:'string',value:'exaPapProItemTtype',text:'项目类型（1总分项、2分项、3分项子项）',dictCode:''})
        fieldList.push({type:'string',value:'exaPapProItemSubTtype',text:'项目子类型（1 2分项：21客观 21主观 23实验实操 24运动）',dictCode:''})
        fieldList.push({type:'int',value:'exaPapProItemLevel',text:'项目级别（1一级默认，2二级，3三级）',dictCode:''})
        fieldList.push({type:'string',value:'exaPapProItemFatherId',text:'上级项目id（默认0）',dictCode:''})
        fieldList.push({type:'int',value:'exaPapProItemOrder',text:'项目序号',dictCode:''})
        fieldList.push({type:'int',value:'izOpen',text:'是否启用',dictCode:''})
        fieldList.push({type:'string',value:'tenantId',text:'学校id',dictCode:''})
        fieldList.push({type:'int',value:'delFlag',text:'0表示未删除,1表示删除',dictCode:''})
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        fieldList.push({type:'date',value:'createTime',text:'创建时间'})
        fieldList.push({type:'string',value:'updateBy',text:'修改人',dictCode:''})
        fieldList.push({type:'date',value:'updateTime',text:'修改时间'})
        this.superFieldList = fieldList
      },
      loadData(arg) {
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        //update-begin--Author:kangxiaolin  Date:20190905 for：[442]主子表分开维护，生成的代码子表的分页改为真实的分页--------------------
        var params = this.getQueryParams();
        let achExamPaperProjectItemVo = {
          examinationPaperId: params.mainId,
          ptype : "1",//ptype = 1,表示排除总分分项获取其余
        }
        getAction(this.url.list, achExamPaperProjectItemVo).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          } else {
            this.dataSource = null;
          }
        })
        //update-end--Author:kangxiaolin  Date:20190905 for：[442]主子表分开维护，生成的代码子表的分页改为真实的分页--------------------

      },

      getOrderMain(record) {
        //其中objectParam中包含AchExaminationPaperList中已选的一条完整试卷数据
        this.queryParam.mainId = record.id;//从对象中获取当选试卷id
        this.queryParam.subjectId = record.subjectId;//从对象中获取当选试卷科目id
        this.loadData(1);
        this.objectModel = record //将试卷AchExaminationPaperList选择的试卷数据record，赋值给objectModel
      },
      handleAdd: function () {
        if (this.objectModel.id === null || this.objectModel.id === ""){
          return alert("请先选择要添加试题的试卷");
        }
        this.$refs.modalForm.title = "添加题型（分项）信息";
        this.$refs.modalForm.add(this.objectModel) //objectModel包含的是当前选择试卷数据
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>